$.post(server_url + "rest/tokenValidate/getSignature.do", {
	"url" : window.location.href.split('#')[0]
}, function(result) {
	token = 
	wx.config({
		debug : false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
		appId : appId, // 必填，公众号的唯一标识
		timestamp : result.timestamp, // 必填，生成签名的时间戳
		nonceStr : result.noncestr, // 必填，生成签名的随机串
		signature : result.signature, // 必填，签名，见附录1
		jsApiList : [ 'checkJsApi', 'chooseImage',  'previewImage', 'uploadImage','downloadImage']
	// 必填，需要使用的JS接口列表，所有JS接口列表见附录2
	});

});
wx.ready(function() {
	wx.checkJsApi({
		jsApiList : [ 'chooseImage', 'previewImage', 'uploadImage','downloadImage'],
		success : function(res) {
			if (res.checkResult.getLocation == false) {
				alert('你的微信版本太低，不支持微信JS接口，请升级到最新的微信版本！');
				return;
			}
		}
	});
});

var form;
var touxiang ='';
$(function() {	

	//$(".my-photo > span").css(width : '50px');
	//$(".my-photo > span").css('background','url(../../images/my2.png) no-repeat');
	layui.use(['layer', 'form'], function() {
		form = layui.form();
		//init();
		initButton();
		initBottom();
	});
	
});

// 页面事件绑定
function initButton() {
	
	
	//绑定其他照片
	$('#addPic').on('click',function(){
		var type = "touxiang";
		var count = 1;
		wx.chooseImage({
		    count: count, // 默认9
		    sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
		    sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
		    success: function (res) {
		        var localIds = res.localIds; // 返回选定照片的本地ID列表，localId可以作为img标签的src属性显示图片
		        var str = "";
		        var urlpic ="";
		        $.each(localIds,function(i,n){		        	
		        	str += '<img src="'+n+'" alt="">';
		        	urlpic += n;
		        	 wx.uploadImage({  
		                 localId: n, // 需要上传的图片的本地ID，由chooseImage接口获得  
		                 isShowProgressTips: 1, // 默认为1，显示进度提示  
		                 success: function (res) {  
		                     var mediaId = res.serverId; // 返回图片的服务器端ID
		                     $.ajax({
		                 		type : "get",
		                 		url : server_url
		                 				+ 'rest/tea/base/uploadImage.do?ran=' + Math.random(),
		                 		dataType : 'json',
		                 		async : true,
		                 		data : {
		                 			token : token,
		                 			mediaId:mediaId,
		                 			component:type
		                 		},
		                 		success : function(result) {
		                 			if (result.retCode == '0000') {
		                 				touxiang = touxiang+result.data;
		                 				 $.ajax({
		     		                 		type : "get",
		     		                 		url : server_url
		     		                 				+ 'rest/tea/info/updateWeixinForuser.do?ran=' + Math.random(),
		     		                 		dataType : 'json',
		     		                 		async : true,
		     		                 		data : {
		     		                 			picpath : touxiang,
		     		                 			usersid:localStorage.getItem('userid')
		     		                 		},
		     		                 		success : function(result) {
		     		                 			if (result.retCode == '0000') {
		     		                 				touxiang = touxiang+result.data;
		     		                 				
		     		                 			}
		     		                 		}
		     		                 	});
		                 			}
		                 		}
		                 	});
		                 } 
		             });  
		        });
		        $(".my-photo > span").css('background','url('+urlpic+') no-repeat');
				$(".my-photo > span").css('width','1.33rem');
				$(".my-photo > span").css('height','1.33rem');
				$(".my-photo > span").css('background-size','contain');
		       // $(".my-photo > span").css('background' : '\'url('+urlpic+')\'');
		       // $("#addPic").html(str);
		    }
		});
	});
	
	
	
	
	
	//跳转到登录页面
	$(".login").bind('click', function() {
		window.location = server_url + "login.do";
	});
	
	// 跳转到我的发布
	$(".my18").bind('click', function() {
		var len = $("#hidenum").html().length;
		if(len == 6 && $("#hidenum").html() == "woaini"){
			window.location = server_url + "myRelease.do";
		}else{
			window.location = server_url + "login.do";
		}
	});
	
	// 跳转到我的资金
	$(".my19").bind('click', function() {
		var len = $("#hidenum").html().length;
		if(len == 6 && $("#hidenum").html() == "woaini"){
			window.location = server_url + "myMoney.do";
		}else{
			window.location = server_url + "login.do";
		}
	});

	// 跳转我的订单
	$(".my20").bind('click', function() {
		var len = $("#hidenum").html().length;
		if(len == 6 && $("#hidenum").html() == "woaini"){
			window.location = server_url + "myOrder.do";
		}else{
			window.location = server_url + "login.do";
		}
	});
	
	// 跳转我的收藏
	$(".my21").bind('click', function() {
		var len = $("#hidenum").html().length;
		if(len == 6 && $("#hidenum").html() == "woaini"){
			window.location = server_url + "myCollection.do";
		}else{
			window.location = server_url + "login.do";
		}
	});
	
	// 跳转历史记录
	$(".my22").bind('click', function() {
		var len = $("#hidenum").html().length;
		if(len == 6 && $("#hidenum").html() == "woaini"){
			window.location = server_url + "myRrecord.do";
		}else{
			window.location = server_url + "login.do";
		}
	});
	
	// 跳转消息中心
	$(".my23").bind('click', function() {
		var len = $("#hidenum").html().length;
		if(len == 6 && $("#hidenum").html() == "woaini"){
			window.location = server_url + "infCenter.do";
		}else{
			window.location = server_url + "login.do";
		}
		
	});

	// 交易土地
	$(".my24").bind('click', function() {
		var len = $("#hidenum").html().length;
		if(len == 6 && $("#hidenum").html() == "woaini"){
			window.location = server_url + "tradingLand.do";
		}else{
			window.location = server_url + "login.do";
		}
		
	});
	
	// 跳转我的设置
	$(".my25").bind('click', function() {
		var len = $("#hidenum").html().length;
		if(len == 6 && $("#hidenum").html() == "woaini"){
			window.location = server_url + "mySet3.do";
		}else{
			window.location = server_url + "login.do";
		}
	
	});
	
	$("#inf").bind('click', function() {
		window.location = server_url + "inf.do";
	});
}
//绑定下列表切换
function initBottom(){
	//跳转到首页
	$("#index").bind('click',function(){
		window.location=server_url+"buyer/product/index.do";
	});
	// 跳转到茶山市场
	$("#tea-market").bind('click', function() {
		window.location = server_url + "teaMarket.do";
	});
	//跳转到头条咨询
	$("#inf").bind('click', function() {
		window.location = server_url + "inf.do";
	});
	//跳转到发布
	$(".demand-btn").bind('click', function() {
		window.location = server_url + "release.do";
	});
}
